package database.team.generator;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class RandomRecordGenerator {
        
        public static void main(String[] args)
        {
                Scanner scanner = new Scanner(System.in);
                
                try{
                        System.out.println("enter the no. of records you want to generate");
                        int numberOfRecords = scanner.nextInt();
                        System.out.println("generating the file...");
                        generateFileWith(numberOfRecords);
                        System.out.println("generated the file with "+numberOfRecords+" records");
                        
                        
                }
                catch(IOException e){
                    e.printStackTrace(); 
                }
                finally{
                scanner.close();
                }
                
                
        }
        
        public static void generateFileWith(int numberOfRecords) throws IOException
        {
                         BufferedWriter fbw;
                         try{
                        	 fbw = new BufferedWriter(new FileWriter("input.txt"));
                         
                         List<String> records=new ArrayList<String>();
                         int id=1000000;
                         for(int i = 0; i < numberOfRecords; i++)
                         {
                        	 
                             String name=null ;
                             int sin=0;
                             String address=null;
                             char alphabets[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','r','s','t','u','v','w','x','y','z'};
                             
                             name = generateString(alphabets,10);
                             
                             sin=(int)(Math.random()*100000000);
                             //to assure length of sin is 9
                             if(sin<100000000)
                             {
                                     sin = sin + 100000000;
                             }

                             address=generateString(alphabets,74);
                             String record=(id+name+sin+address);
                             records.add(record);
                             id++;
                         }
                         Collections.shuffle(records);
                         for(String writeRecord: records)
                         {
                        	 
                         fbw.write("" + writeRecord);
                         fbw.newLine();
                         }
                         fbw.close();
                         }
                         catch(NullPointerException e)
                         {
                        	 e.printStackTrace();
                         }
        
        }
        
        
        public static String generateString(char alphabets[],int length)
        {
                
                String value="";
                for (int i=0;i<(length-1);i++)
                {
                        int randomNumber=(int)(Math.random()*25);
                        value=value+alphabets[randomNumber];
                }
                return value;
        }
        
}




/*
package database.team.generator;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class RandomRecordGenerator {
	
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		try{
			System.out.println("enter the no. of records you want to generate");
			int numberOfRecords = scanner.nextInt();
			System.out.println("generating the file...");
			generateFileWith(numberOfRecords);
			System.out.println("generated the file with "+numberOfRecords+" records");
			
			
		}
		catch(IOException e){
			e.printStackTrace();
			
			}
		
	}
	
	public static void generateFileWith(int numberOfRecords) throws IOException
	{
			 BufferedWriter fbw = new BufferedWriter(new FileWriter("input.txt"));
			 for(int i = 0; i < numberOfRecords; i++)
			 {
				 fbw.write("" + generateRecord());
				 fbw.newLine();
			 }
			 fbw.close();
	
	}
	
	public static String generateRecord()
	{
		int id=0;
		String name=null ;
		int sin=0;
		String address=null;
		char alphabets[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','r','s','t','u','v','w','x','y','z'};
		
		id = (int)(Math.random()*1000000);
		//to assure length of id is 7
		if (id<1000000)
		{
			id = id + 1000000;
		}
		name = generateString(alphabets,10);
		
		sin=(int)(Math.random()*100000000);
		//to assure length of sin is 9
		if(sin<100000000)
		{
			sin = sin + 100000000;
		}

		address=generateString(alphabets,74);
		String record=(id+name+sin+address);
		return record;
	
	}
	
	public static String generateString(char alphabets[],int length)
	{
		
		String value="";
		for (int i=0;i<(length-1);i++)
		{
			int randomNumber=(int)(Math.random()*25);
			value=value+alphabets[randomNumber];
		}
		return value;
	}
	
}
*/